package com.health.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.health.entity.BannedUsers;
import com.health.entity.User;
import com.health.entity.pojo.dto.QueryBanDTO;
import com.health.mapper.BannedUsersMapper;
import com.health.service.IBannedUsersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sanchuan
 * @since 2023-04-22
 */
@Service
public class BannedUsersServiceImpl extends ServiceImpl<BannedUsersMapper, BannedUsers> implements IBannedUsersService {

    @Autowired
    private BannedUsersMapper bannedUsersMapper;

    @Override
    public List<BannedUsers> listBanUser() {
        return bannedUsersMapper.listBanUser();
    }

    /**
     * 封禁列表分页+条件查询
     * @param pageNum
     * @param pageSize
     * @param queryBanDTO
     * @return
     */
    @Override
    public IPage<BannedUsers> listBanUsersPage(Integer pageNum, Integer pageSize, QueryBanDTO queryBanDTO) {
        List<BannedUsers> bannedUsers = bannedUsersMapper.listBanUsersPage(queryBanDTO);
        List<BannedUsers> list = new ArrayList<>();
        int curIdx = pageNum > 1 ? (pageNum - 1) * pageSize : 0;
        for (int i = 0; i < pageSize && curIdx + i < bannedUsers.size(); i++) {
            list.add(bannedUsers.get(curIdx + i));
        }
        IPage<BannedUsers> iPage = new Page<>(pageNum,pageSize);
        iPage.setRecords(list);
        iPage.setTotal(bannedUsers.size());
        return iPage;
    }
}
